package com.example.SpringBootRestful.controller;

import com.example.SpringBootRestful.entity.User;
import com.example.SpringBootRestful.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;
@Controller
@CrossOrigin
public class UserController {

//todo: 在下面Controller 实现一个接口满足以下要求
// 1. 实现一个Get请求,查出所有的用户信息
// 2. 接口访问地址：（/api/users）
// 3. 使用注解：@CrossOrigin实现跨域请求。
    @Autowired
    UserService userService;
    @GetMapping("/api/users")
    public ResponseEntity  getAllUsers(){
        List<User> allUser = userService.getAllUser();
        return new ResponseEntity(allUser,HttpStatus.OK);
    }
}
